<html lang="en" dir="ltr">

<head>
  <meta charset="utf-8">
  <title></title>
  <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
  <script src="https://cdn.bootcss.com/vue/2.5.17-beta.0/vue.min.js"></script>
  <style media="screen">
    img{
      width: 50;
      height:50;
      margin-right: 5
    }
  </style>
</head>
<body>
  <div id="view" >
    分数：{{score}}

    <cust num="0" v-on:change="change"></cust>
    <cust num="3" v-on:change="change"></cust>
    <cust num="2" v-on:change="change"></cust>
    <cust num="1" v-on:change="change"></cust>
    <cust num="5" v-on:change="change"></cust>
  </div>

  <script type="text/javascript">
      Vue.component('cust',{
          template:`<div>
              <img @click="press(i)" v-for="i of 5" v-if="i <= num2" src="./selected.png"></img>
              <img @click="press(i)" v-else src="./unselect.png"></img>
              <br>
          </div>`,
          props:["num"],
          data:function() {
              return{
                num2:this.num
              }
          },
          methods:{
            press(i){
              this.num2 = i;
              this.$emit("change",this.num2);
            }
          }
      })

      const vm = new Vue({
        el:'#view',
        data:{
          score:0
        },
        methods:{
          change(v){
            this.score = v;
          }
        }
      })
  </script>
</body>

</html>
